package Testing;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;

import com.sun.corba.se.spi.activation.Server;

import monsterRun.client.model.Facade;
import monsterRun.client.model.GameBoard;
import monsterRun.client.model.entities.PlayerEntity;
import monsterRun.client.view.MonsterFrame;
import monsterRun.client.view.renderer.RendererPanel;
import monsterRun.common.model.Position;
import monsterRun.common.model.enums.Direction;
import monsterRun.common.model.enums.GameBoardType;
import monsterRun.common.model.enums.GameMode;

public class PlayerCallBackImpl extends UnicastRemoteObject implements
		PlayerCallBackInterface
{
	private int playerID;
	private int startPos = -1;
	private Facade facade;
	private RendererPanel renderer = null;
	private MonsterFrame frame = null;
	private GameBoard gameBoard;

	private PlayerEntity player;

	public PlayerCallBackImpl(int playerID, Facade facade,
			RendererPanel renderer, MonsterFrame frame, GameBoard gameBoard)
			throws RemoteException
	{
		super();
		this.playerID = playerID;
		this.facade = facade;
		this.renderer = renderer;
		this.frame = frame;
		this.gameBoard = gameBoard;
	}

	@Override
	public void hello()
	{
		System.out.println("Player: " + playerID + "Says hello");
	}

	public void startPositionsResponse(ArrayList<Integer> positions)
	{

	}

	@Override
	public void gameStart(GameBoardType boardStyle) throws RemoteException
	{

		facade.initializeGameBoard(boardStyle);
		renderer.redrawBoard();
		frame.hidePopups();
		facade.enableKeyListener(true);

	}

	public void setRenderPanel(RendererPanel renderPanel)
	{
		this.renderer = renderPanel;
	}

	public void setFrame(MonsterFrame frame)
	{
		this.frame = frame;
	}

	public Facade getFacade()
	{
		return facade;
	}

	public void setFacade(Facade facade)
	{
		this.facade = facade;
	}

	public void setPlayerID(int playerID)
	{
		this.playerID = playerID;
	}

	public int getPlayerID()
	{
		return playerID;
	}

	@Override
	public void playerConnect(int id, Position position, Direction direction,
			int num)
	{
		gameBoard.clientConnected(id, position, direction, num);
	}

	@Override
	public void monsterMoved(Position position) throws RemoteException
	{
		gameBoard.monsterMoved(position);

	}

	@Override
	public void playerMoved(int playerId, Position position, int direction)
			throws RemoteException
	{

		gameBoard.clientMoved(playerId, position, direction);
	}

	@Override
	public void gameFinished(int playerId) throws RemoteException
	{
		frame.gameFinished(playerId);

	}

	public void playerDead(int playerId)
	{
		gameBoard.playerDead(playerId);
	}

}
